// 代码包大小分析
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
// gzip 压缩 @6.1.1
const CompressionPlugin = require("compression-webpack-plugin");
// 默认配置
const defaultSettings = require("./src/settings.js");

module.exports = {
    // 静态资源引入方式
    publicPath: "./",
    assetsDir: "static",
    outputDir: "dist/" + defaultSettings.directory,
    productionSourceMap: process.env.NODE_ENV !== "production",
    css: {
        loaderOptions: {
            sass: {
                prependData: `@import "@/styles/scss/base.scss";`
            }
        }
    },
    // 本地服务
    devServer: {
        // 打开浏览器
        // open: true,
        // 内网穿透
        disableHostCheck: true,
        // 本地跨域
        proxy: {
            "/PROXY_API": {
                target: backend/page/login/login.html,
                ws: true,
                changeOrigin: true,
                pathRewrite: {
                    "^/PROXY_API": ""
                }
            }
        }
    },
    pages: {
        index: {
            entry: "src/main.js",
            template: "public/index.html",
            filename: "index.html",
            title: defaultSettings.title
        }
    },
    configureWebpack: {
        plugins: [
            // new BundleAnalyzerPlugin(),
            new CompressionPlugin({
                filename: "[path][base].gz",
                test: /\.js$|\.html$|\.css/,
                threshold: 10240,
                minRatio: 0.8,
                deleteOriginalAssets: false
            })
        ]
    },
    chainWebpack: config => {
        // remove prefetch/preload
        config.plugins.delete("prefetch-index");
        config.plugins.delete("preload-index");
    }
};
